package cn.anecansaitin.whimsy.util;

import net.minecraft.world.entity.Entity;
import net.minecraft.world.phys.AABB;
import org.joml.Vector3f;

public class AABBUtil {
    /**
     * @param moving 正在高速移动的实体
     * @param target 需要判断的目标实体
     * @return 判断正在移动的实体是否与目标实体有碰撞
     */
    public static boolean isMovingEntityCollisionWithEntity(Entity moving, Entity target, double inflate) {
        Vector3f start = moving.position().toVector3f();
        Vector3f end = new Vector3f(start).add(moving.getDeltaMovement().toVector3f());
        Vector3f foot = MathUtil.perpendicularFootOfPointToLine(start, end, target.position().toVector3f());
        AABB movingBox = moving.getBoundingBox().move(foot.x, foot.y, foot.z);
        AABB targetBox = target.getBoundingBox().move(target.position()).inflate(inflate);
        return movingBox.intersects(targetBox);
    }
}
